package tatrus;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;

/**
 * <p>Title: HighScore </p>
 * <p>Description: CSIS 343 Course Project</p>
 * 
 * This class is used to store the name and score 
 * of any player that earns a top 10 high score.  
 * 
 * @author Nick Brown
 * @email  nicholas.brown@my.uwrf.edu
 * @author John Wagner 
 * @email  john.wagner@my.uwrf.edu
 * 
 * @date November 28th 2013
 *
 */

@Entity
public class HighScore
{
	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private long id;
	
	private String name;
	private int score;
	
	/**
	 * Default constructor.  This only exists so that
	 * the database software is operational.  
	 */
	public HighScore()
	{
		name = null;
		score = 0;
	}
	
	/**
	 * Creates a HighScore object with the specified information.   
	 * 
	 * @param name The name of the player
	 * 
	 * @param score The score the player earned
	 */
	public HighScore(String name, int score)
	{
		this.name = name;
		this.score = score;
	}
	
	/**
	 * Returns the score for this player.
	 * 
	 * @return The score that the player earned
	 */
	public int getScore()
	{
		return score;
	}
	
	/**
	 * Overridden toString method used to format the information
	 * displayed by the JList in HighScoreManager class.  
	 */
	public String toString() 
	{
		String scoreFormat = String.valueOf(score);
		int length = scoreFormat.length();
		String padding = "";
		
		for(int i = 0; i < 10 - length; i ++)
		{
			padding += " ";
		}
		
		return String.format("   %-20s  %s  %10d", name, padding, score);
	}
}